﻿using UnityEngine;

namespace UFrame
{
    public class EffectMa : MaMono<EffectMa>
    {
        public static string layer = "Effect";

        public static GameObject PlayEffect(string path, Vector3 position)
        {
            var effect = PlayEffect(path);
            effect.transform.position = position;
            return effect;
        }

        public static GameObject PlayEffect(string path, Transform parent = null)
        {
            GameObject effect = null;
            GameObject effectData = ResourcesMa.Load<GameObject>(path);

            if (parent)
            {
                effect.transform.position = Vector3.zero;
                effect.transform.SetParent(parent, false);
            }

            effect = Instantiate(effectData);
            effect.layer = LayerMask.NameToLayer(layer);
            var sr = effect.GetComponent<SpriteRenderer>();
            if (sr != null)
            {
                sr.sortingOrder = SortingLayer.GetLayerValueFromName(layer);
            }

            return effect;
        }
    }
}